# @Time : 2020/6/24 17:00
# @Author : Fioman 
# @Phone : 13149920693
from collections import namedtuple

City = namedtuple("City", 'name,country population,coordinates')
tokyo = City("Tokyo","JP",36.933,(35.689722,139.691667))
print("tokyo = {}".format(tokyo))

print("population = ",tokyo.population)
print("coordinates = ",tokyo.coordinates)
print("tokyo[1] = {}".format(tokyo[1]))

# 具名元组的属性和方法
print("_fields属性 = {}".format(City._fields))

LatLong = namedtuple('LatLong','lat long')
delhi_data = ("Delhi NCR",'IN',21.935,LatLong(28.613889,77.208889))
delhi = City._make(delhi_data)
print("_asdict属性 = {}".format(delhi._asdict()))

for key,value in delhi._asdict().items():
    print(key + ":",value)

